import QtQuick 2.14
import QtQuick.Window 2.14


Rectangle{
    id: root
    width: 300
    height: 300

    Text {
        id: thisLabel
        x: 24 ;y: 16
        height: 2 * width
        Rectangle{
            anchors.fill: parent;
            color: 'orange'
            z: parent.z-1
        }

        property int times: 24
    //取别名
        property alias anotherTimes: thisLabel.times

        text: "thisLabel "+anotherTimes
    //设置字体大小
        font.family: "Ubuntu"
        font.pixelSize: 24
    //
        KeyNavigation.tab: thatLabel

        onHeightChanged: console.log('height',height)

        focus: true

        color: focus ? 'red':'black'
    }

    Text {
        id: thatLabel
        text: "thatLabel "+thisLabel.times
        focus: !thisLabel.focus
        KeyNavigation.tab: thisLabel
        color: focus ? 'red':'black'

        onTextChanged: (text)=>/*function(text)*/ {console.log('text changed to:',text)}

        //按下空格键
        Keys.onSpacePressed: {increment()}
        Keys.onEscapePressed: {text= ''}
        //js函数
        function increment(){
            thisLabel.times+=1
        }
    }
}
